package cn.frontop.funswitch.service.impl;

import cn.frontop.funswitch.dao.ApiPathDao;
import cn.frontop.funswitch.entity.ApiPathEntity;
import cn.frontop.funswitch.entity.IndexConfigEntity;
import cn.frontop.funswitch.service.ApiPathService;
import cn.frontop.funswitch.service.IndexConfigService;
import cn.frontop.funswitch.util.CommonUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author Yun
 */
@Service("apiPathService")
public class ApiPathServiceImpl extends ServiceImpl<ApiPathDao, ApiPathEntity> implements ApiPathService {
    @Autowired
    IndexConfigService indexConfigService;

    @Override
    public Object apiTest(ApiPathEntity apiPathEntity, JSONObject request) {
        IndexConfigEntity indexConfigEntity = indexConfigService.getById(apiPathEntity.getIndexId());
        return CommonUtil.testProcess(apiPathEntity, indexConfigEntity == null || StrUtil.isEmpty(indexConfigEntity.getMock()) ? new JSONObject() : JSONUtil.parseObj(indexConfigEntity.getMock()), indexConfigService);
    }
}